package com.taotao.apitype;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class ApiHepler {

	/**
	 * 普通消息对象
	 * 
	 * @author Administrator
	 *
	 */
	public static class MessageResult {
		private String info;

		public String getInfo() {
			return info;
		}

		public Boolean getIsOK() {
			return isOK;
		}

		public Object getData() {
			return data;
		}

		private Boolean isOK;
		private Object data;
	}

	/**
	 * 分页返回对象
	 * 
	 * @author Administrator
	 *
	 */
	public static class PagingResponse<T> {
		private List<T> data;

		public List<T> getData() {
			return data;
		}

		public long getTotal() {
			return total;
		}

		public long total;
	}

	/**
	 * 分页请求对象
	 * 
	 * @author Administrator
	 *
	 */
	public static class PagingResult {
		@Override
		public String toString() {
			return "PagingResult [page=" + page + ", size=" + size + "]";
		}

		private Integer page;

		public Integer getPage() {
			return page == null ? 1 : page;
		}

		public void setPage(Integer page) {
			this.page = page;
		}

		public Integer getSize() {
			return size == null ? 20 : size;
		}

		public void setSize(Integer size) {
			this.size = size;
		}

		private Integer size;
	}

	/**
	 * 获取时间
	 * 
	 * @return
	 */
	public static String getTime() {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 设置日期格式
		return df.format(new Date());// new Date()为获取当前系统时间
	}

	/**
	 * 输出分页信息
	 * 
	 * @param rows
	 * @param total
	 * @return
	 */
	public static <T> PagingResponse<T> Paging(List<T> rows, long total) {
		// getResponse().setContentType("text/json;charset=utf-8");
		PagingResponse<T> pagingResult = new PagingResponse<T>();
		pagingResult.data = rows;
		pagingResult.total = total;
		return pagingResult;
	}

	/**
	 * 输出提示信息
	 * 
	 * @param Message
	 * @param result
	 * @param isOK
	 * @return
	 */
	public static MessageResult MessBox(String message, Boolean isOK, Object data) {
		MessageResult messageResult = new MessageResult();
		messageResult.data = data;
		messageResult.info = message;
		messageResult.isOK = isOK;
		return messageResult;
	}
}
